package com.cdplife.ci.modular.system.timer;

import com.cdplife.ci.modular.system.service.IPolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务
 * @author Jers
 * 2018-11-19
 */
@Component
@EnableScheduling
@Service
@Transactional
public class ScheduledService {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    private IPolicyService policyService;

    /**
     * @brief fixedRate = 10000表示每隔10000ms，Spring scheduling会调用一次该方法，不论该方法的执行时间是多少
     * @throws InterruptedException
     */
    @Scheduled(fixedRate = 10000)
    public void printCurrentTime() throws InterruptedException {}

    /**
     * @brief fixedDelay = 10000表示当方法执行完毕10000后，Spring scheduling会再次调用该方法
     * @throws InterruptedException
     */
    @Scheduled(fixedDelay = 10000)
    public void printCurrentTimeAfterSleep() throws InterruptedException {}

    /**
     * @brief 每日凌晨1点执行的任务
     * @throws InterruptedException
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void printCurrentTimeCron() throws InterruptedException {
        //变更保单状态
        policyService.changePolicyStatus();

    }


}